package com.example.leavejava.controller;

import com.example.leavejava.Result;
import com.example.leavejava.domain.Add;
import com.example.leavejava.domain.Search;
import com.example.leavejava.mapper.Leave;
import com.example.leavejava.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
public class LeaveController {
    @Autowired
    private Leave leave;

    @Resource
    private LeaveService leaveService;

    @RequestMapping(value = "/add")
    public Result Add(@RequestBody Add add){
        Result result = new Result();
        try {
           return leaveService.AddLeave(add);
        }catch (Exception e){
            e.printStackTrace();
            result.setResult("error");
            result.setMsg("无法评论");
        }
        return  result;
    }

    @RequestMapping(value = "/search")
    public Result Search(@RequestBody Search search){
        Result result = new Result();
        try {
            return leaveService.SearchLeave(search);
        }catch (Exception e){
            e.printStackTrace();
            result.setResult("error");
            result.setMsg("无法查询");
        }
        return  result;
    }


}
